package org.softwarepoets.emf.ecore.editor.extensions;

import org.eclipse.emf.ecore.EAnnotation;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EOperation;
import org.eclipse.emf.ecore.EcoreFactory;
import org.eclipse.emf.ecore.EcorePackage;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.InputDialog;
import org.eclipse.ui.PlatformUI;

public class CreateNamedConstraints extends AbstractExtensionAction {

	public CreateNamedConstraints() {
		super(EClass.class);
	}

	@Override
	public void run(IAction action) {
		InputDialog dialog = new InputDialog(PlatformUI.getWorkbench()
				.getActiveWorkbenchWindow().getShell(),
				"Enter Constraint names seperated by a space", "", "", null);

		if (dialog.open() == InputDialog.OK) {
			EClass object = (EClass) element;
			String constraints = dialog.getValue();
			EAnnotation eAnnotation = EcoreFactory.eINSTANCE
			.createEAnnotation();
			object.getEAnnotations().add(eAnnotation);
			eAnnotation.setSource("http://www.eclipse.org/emf/2002/Ecore");
			eAnnotation.getDetails().put("constraints", constraints);
		}
	}

}
